﻿using System;
using System.Collections.Generic;
using System.Text;
using log4net;

namespace Cms.EntLib
{
    /// <summary>
    /// 日志辅助类
    /// </summary>
    public class LogHelper
    {
        private static ILog log;
        private static LogHelper logHelper = null;
        /// <summary>
        /// 初始化
        /// </summary>
        /// <returns></returns>
        public static ILog GetInstance()
        {
            logHelper = new LogHelper(null);
            return log;
        }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <returns></returns>
        public static ILog GetInstance(Type type)
        {
            logHelper = new LogHelper(type);
            return log;
        }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="configPath"></param>
        /// <returns></returns>
        public static ILog GetInstance(string configPath)
        {
            logHelper = new LogHelper(configPath, null);
            return log;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="configPath"></param>
        private LogHelper(string configPath, Type type)
        {
            if (type == null)
                type = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;
            log = log4net.LogManager.GetLogger(type);
            if (!string.IsNullOrEmpty(configPath))
                log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(configPath));
        }
        private LogHelper(Type type)
            : this(null, type)
        {

        }

    }
}
